package com.ruoyi.master.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.master.domain.TaskFavorite;
import com.ruoyi.master.service.ITaskFavoriteService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 任务收藏夹Controller
 * 
 * @author jiandan
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/favorite")
public class TaskFavoriteController extends BaseController
{
    @Autowired
    private ITaskFavoriteService taskFavoriteService;

    /**
     * 查询任务收藏夹列表
     */
    @RequiresPermissions("master:favorite:list")
    @GetMapping("/list")
    public TableDataInfo list(TaskFavorite taskFavorite)
    {
        startPage();
        List<TaskFavorite> list = taskFavoriteService.selectTaskFavoriteList(taskFavorite);
        return getDataTable(list);
    }

    /**
     * 导出任务收藏夹列表
     */
    @RequiresPermissions("master:favorite:export")
    @Log(title = "任务收藏夹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskFavorite taskFavorite)
    {
        List<TaskFavorite> list = taskFavoriteService.selectTaskFavoriteList(taskFavorite);
        ExcelUtil<TaskFavorite> util = new ExcelUtil<TaskFavorite>(TaskFavorite.class);
        util.exportExcel(response, list, "任务收藏夹数据");
    }

    /**
     * 获取任务收藏夹详细信息
     */
    @RequiresPermissions("master:favorite:query")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(taskFavoriteService.selectTaskFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增任务收藏夹
     */
    @RequiresPermissions("master:favorite:add")
    @Log(title = "任务收藏夹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskFavorite taskFavorite)
    {
        return toAjax(taskFavoriteService.insertTaskFavorite(taskFavorite));
    }

    /**
     * 修改任务收藏夹
     */
    @RequiresPermissions("master:favorite:edit")
    @Log(title = "任务收藏夹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskFavorite taskFavorite)
    {
        return toAjax(taskFavoriteService.updateTaskFavorite(taskFavorite));
    }

    /**
     * 删除任务收藏夹
     */
    @RequiresPermissions("master:favorite:remove")
    @Log(title = "任务收藏夹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(taskFavoriteService.deleteTaskFavoriteByFavoriteIds(favoriteIds));
    }
}
